#!/bin/sh -e

# Support for vulkan drivers of intel, amd, and broadcom. Change if you just
# want to specify your own graphics card.
vulkan_drivers=amd,intel,broadcom

# Temporarily install python-mako to build mesa
(
    cd mako

    python3 setup.py build
    python3 setup.py install \
        --prefix=/usr \
        --root="$PWD/dist"

)

PYTHONPATH=$(./pythonpath)

export PYTHONPATH
export DESTDIR="$1"

# Fix issues with musl and firefox.
# https://bugs.freedesktop.org/show_bug.cgi?id=35268
# https://github.com/mesa3d/mesa/commit/9f37c9903b87f86a533bfaffa72f0ecb285b02b2
clsed "/pre_args += '-DUSE_ELF_TLS'/d" meson.build

python3 bin/git_sha1_gen.py --output include/git_sha1.h

cl-meson \
    -Dplatforms=x11,wayland \
    -Dexpat=enabled \
    -Ddri3=enabled \
    -Degl=enabled \
    -Dgbm=enabled \
    -Dgles1=enabled \
    -Dgles2=enabled \
    -Dglx-read-only-text=true \
    -Dglx=dri \
    -Dllvm=enabled \
    -Dshared-glapi=enabled \
    -Dvulkan-drivers="$vulkan_drivers" \
    -Dxmlconfig=enabled \
    -Dzstd=disabled \
    . output

ninja -C output
ninja -C output install
